package com.iss.examsys.ejb;

import com.iss.examsys.entity.SectionTag;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author MA
 */
@Stateless
public class SectionTagBean {
    @PersistenceContext EntityManager em;

    public void create(SectionTag entity){
        em.persist(entity);
    }
    
    public void edit(SectionTag entity) {
        em.merge(entity);
    }
    
    public void remove(SectionTag entity) {
        em.remove(em.merge(entity));
    }
    
    public SectionTag findById(Long id){        
        SectionTag entity = em.find(SectionTag.class, id);        
        return entity;
    }
    
    public List<SectionTag> findAll(){
        TypedQuery<SectionTag> result = em.createNamedQuery("SectionTag.findAll", SectionTag.class);        
        return result.getResultList();
    } 
    
    public List<SectionTag> findBySectionId(Long sectionId){
        TypedQuery<SectionTag> result = em.createNamedQuery("SectionTag.findBySectionId", SectionTag.class);
        result.setParameter("sectionId", sectionId);
        return result.getResultList();
    }
    
    public List<SectionTag> findByTagId(Long tagId){
        TypedQuery<SectionTag> result = em.createNamedQuery("SectionTag.findByTagId", SectionTag.class);
        result.setParameter("tagId", tagId);
        return result.getResultList();
    }
}
